package stone.ast;

import java.util.List;

import ASTInterpreter.Environment;

public class WhileStmnt extends ASTList {

	public WhileStmnt(List<ASTree> list) {
		super(list);
	}
	
	public ASTree condition() {
		return child(0);
	}
	
	public ASTree body() {
		return child(1);
	}
	
	public Object eval(Environment env) {
		Object result = 0;
		for(;;) {
			Object c = condition().eval(env);
			if (c instanceof Integer && ((Integer)c).intValue() == FALSE) {
				return result;
			}
			else {
				result = body().eval(env);
			}
		}
	}
	
	public String toString() {
		return "(while " + condition() + " " + body() + ")";
	}

}
